package com.zzptc.zzsgz.bdsjws.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.UpdateVersionFragment;
import com.zzptc.zzsgz.bdsjws.vo.VersionInfo;

import butterknife.BindView;
import butterknife.OnClick;

public class NewActivity extends BaseActivity {


    @BindView(R.id.tl_newbar)
    Toolbar tlNewbar;
    @BindView(R.id.ly_update2)
    LinearLayout lyUpdate2;
    @BindView(R.id.activity_new)
    RelativeLayout activityNew;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(tlNewbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_new;
    }

    @Override
    public void initData() {
    }

    @Override
    public void intView() {

    }


    @OnClick(R.id.ly_update2)
    public void onViewClicked() {
       // Intent intent = new Intent(this, Update2Activity.class);
        //startActivity(intent);
        startActivityForResult(new Intent(this,Update2Activity.class),0);
    }
    public void showDialog(String string){
        FragmentManager fr=getFragmentManager();
        UpdateVersionFragment ul=UpdateVersionFragment.getUpdateVersionFragment(string);
        ul.show(fr,"");
    }

    //接收   onActivityResul接收方
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                Toast.makeText(this, "有网络，比较慢", Toast.LENGTH_SHORT).show();
                showDialog("有网络，比较慢");
                break;
            case 2:
                Toast.makeText(this, "网络不通请检查网络", Toast.LENGTH_SHORT).show();
                showDialog("无网络");
                break;
            case 3:
                //接收(第二个参数和第三个参数是传过来的值)
                VersionInfo versionInfo=(VersionInfo)data.getSerializableExtra("VersionInfo");//Activity中已经得到了
                Toast.makeText(this, versionInfo.getApkurl()+"", Toast.LENGTH_SHORT).show();
                Toast.makeText(this, "有网络，请下载", Toast.LENGTH_SHORT).show();
                FragmentManager fra=getFragmentManager();//通过传参给对话框
                UpdateVersionFragment update=UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
                //终于让对话框出现了
                update.show(fra,"");
                break;
            case 4:
                Toast.makeText(this, "最新版本，无需更新", Toast.LENGTH_SHORT).show();
                showDialog("最新版本，无需更新");
                break;
        }
    }
}
